/**
 * Perm.java created by zhangzhidong 
 * at 下午10:32:13 2015年9月12日
 */
package algorithm;

import java.util.Arrays;

public class PermCom {
	int[] data = new int[] { 1, 2, 3, 4, 5 };

	public void perm(int k, int m) {
		if (k == m) {
			for (int i = 0; i <= m; i++) {
				System.out.print(data[i] + ",");
			}
			System.out.println();
		} else {
			for (int i = k; i <= m; i++) {
				swap(k, i);
				perm(k + 1, m);
				swap(k, i);
			}
		}
	}

	public void swap(int k, int i) {
		int temp = data[k];
		data[k] = data[i];
		data[i] = temp;

	}

	public void combine(int num) {
		combine(num, 0, new int[num], 0);
	}

	private void combine(int k, int start, int res[], int ptr) {
		if (ptr == res.length) {
			System.out.println(Arrays.toString(res));
			return;
		}
		if (start == data.length)
			return;
		res[ptr] = data[start];
		combine(k, start + 1, res, ptr + 1);
		combine(k, start + 1, res, ptr);
	}

	public static void main(String[] args) {
		// new Perm().perm(0, 4);
		PermCom p = new PermCom();
		p.combine(4);
		// 5 choose 3 to combine
		// p.combine(3, 0,new int[3],0);
		// p.combine(3,0,new int[3],0);

	}

}
